
//  ZWalletAccount.m
//  NewProject
//
//  Created by Apple on 2018/5/19.
//  Copyright © 2018年 chenIos. All rights reserved.
//

#import "ZWalletAccount.h"
@implementation ZWalletAccountInfo
MJCodingImplementation

@end
@implementation ZWalletAccount
MJCodingImplementation
- (NSString *)currentCurrrencyUnit
{
    if (!_currentCurrrencyUnit) {
        _currentCurrrencyUnit = @"CNY";
    }return _currentCurrrencyUnit;
}
- (NSArray *)currencyUnit
{
    if (!_currencyUnit) {
        _currencyUnit = @[@"CNY",@"USD"];
    }return _currencyUnit;
}
+ (NSDictionary *)mj_objectClassInArray
{
    return @{@"allWallets":@"ZWalletAccountInfo"};
}
//- (NSMutableArray *)allWallets
//{
//    if (!_allWallets) {
//        _allWallets = [NSMutableArray array];
//    }return _allWallets;
//}
//
//+ (void)timer{
//    static NSTimer *timer;
//    if (timer) {
//        [timer invalidate];
//        timer = nil;
//    }
//    timer = [NSTimer timerWithTimeInterval:60 target:self selector:@selector(qureyAccoutInfo) userInfo:nil repeats:YES];
//    [[NSRunLoop mainRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
//    [timer fire];
//}

//+ (void)qureyAccoutInfo{
//    ZWalletAccount *wallet = [ZWalletAccount wallet];
//    if (wallet) {
//        for (ZWalletAccountInfo *account in wallet.allWallets) {
//            __weak typeof(account) weakAccout = account;
//
//            [ZGRPC_Manager checkPkAddress:weakAccout.walletAdress Completion:^(long long pkcoin, NSInteger status) {
//                if (status == 0) {
//                    weakAccout.pais = [NSString stringWithFormat:@"%.8lf",pkcoin/(double)PAIS_SCALE];
//                    weakAccout.paisNum = pkcoin;
//                    [ZDBManager changePkCoin:weakAccout.walletAdress coin:pkcoin coinString:weakAccout.pais];
//                    [[NSNotificationCenter defaultCenter] postNotificationName:@"z_wallet_pais_change" object:nil];
//                }
//            }];
//
//        }
//    }
//
//}

+ (ZWalletAccount *)wallet
{
    static ZWalletAccount *walletA;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        walletA = [ZWalletAccount new];
        
        NSString *current = [[NSUserDefaults standardUserDefaults] objectForKey:@"currentCurrrencyUnit"];
        if (current) {
            walletA.currentCurrrencyUnit = current;
        }
        
    });
    return walletA;
}
//+ (ZWalletAccount *)getWallet
//{
//    NSString *path =     [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject stringByAppendingPathComponent:@"z_chx_create_wallet_data"];
//    path = [path stringByAppendingPathComponent:@"wallet"];
//    BOOL isExist =   [[NSFileManager defaultManager] fileExistsAtPath:path];
//    if (isExist) {
//        return [NSKeyedUnarchiver unarchiveObjectWithFile:path];
//    }
//    return nil;
//}
//- (void)writeToFile
//{
//    NSString *path =     [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject stringByAppendingPathComponent:@"z_chx_create_wallet_data"];
//    BOOL isDirectory;
//    BOOL success = [[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&isDirectory];
//    if (isDirectory&&success) {
//        path = [path stringByAppendingPathComponent:@"wallet"];
//        success = [NSKeyedArchiver archiveRootObject:self toFile:path];
//        if (success) {
//            ZWLog(@"写入成功");
//        }
//    }else
//    {
//        NSError *error ;
//        success =  [[NSFileManager defaultManager]createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error];
//        if (success) {
//            path = [path stringByAppendingPathComponent:@"wallet"];
//            [NSKeyedArchiver archiveRootObject:self toFile:path];
//        }else
//        {
//            ZWLog(@"error %@",error.userInfo);
//        }
//    }
//}
@end
